package com.hoyue.dao.impl;

import java.sql.SQLException;

import java.util.List;

import com.hoyue.bean.Introduction;
import com.hoyue.dao.IntroductionDao;
import com.hoyue.utils.C3P0Utils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

public class IntroductionDaoImpl implements IntroductionDao{
    QueryRunner qr = C3P0Utils.getQueryRunner();

    @Override
    public void updateIntro(Introduction introduction) throws SQLException {
        String sql = "update introduction set title = ? , content = ? where id = ?";

        qr.update(sql,introduction.getTitle(),introduction.getContent(),introduction.getId());
    }

    @Override
    public List<Introduction> getAllIntro() throws SQLException {
        String sql = "select * from introduction";

        return qr.query(sql,new BeanListHandler<>(Introduction.class));
    }
}